﻿using Levfier.GUI.EditorControls.Parameters;
using Levfier.Proccessors.Measuring;
using Levfier.Proccessors.Parameters;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;

namespace Levfier.GUI.EditorControls.Measuring
{
    /// <summary>
    /// ProccessorPropertyEditorView.xaml の相互作用ロジック
    /// </summary>
    [Serializable]
    public partial class SpectrumAnalyzerView : UserControl
    {
        /// <summary>
        /// パラメータテーブル
        /// </summary>
        private IDictionary<string, ProccessParameter> parameters;

        /// <summary>
        /// データソース
        /// </summary>
        private SpectrumAnalyzer analyzer;

        /// <summary>
        /// ウィンドウ
        /// </summary>
        private Window window;

        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="parameters">パラメータテーブル</param>
        public SpectrumAnalyzerView(SpectrumAnalyzer analyzer, IDictionary<string, ProccessParameter> parameters)
        {
            InitializeComponent();
            this.parameters = parameters;
            this.analyzer = analyzer;
        }

        /// <summary>
        /// ボタン押下時の動作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if ((bool)this.viewButton.IsChecked)
            {
                if (null == this.window)
                {
                    this.window = new SpectrumAnalyzerWindow(new SpectrumBitmapDrawer(this.analyzer), this.analyzer.GetParameters());
                    this.window.Closed += Window_Closed;
                    this.window.Show();
                }
                else
                {
                    this.window.Visibility = Visibility.Visible;
                }
            }
            else
            {
                if (null == this.window)
                {
                }
                else
                {
                    this.window.Visibility = Visibility.Hidden;
                }
            }
        }

        /// <summary>
        /// アナライザウィンドウが閉じられた場合の動作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closed(object sender, EventArgs e)
        {
            this.window = null;
        }

        /// <summary>
        /// 削除時の動作
        /// </summary>
        public void Delete()
        {
            if (null == this.window)
            {
            }
            else
            {
                this.window.Close();
            }
        }
    }
}
